﻿/**
 * This is a part of MCServe, which is available under the Apache license 2.0.
 * With this code, you may do whatever you want as long as that is not in conflict with this license.
 * In addition, you should have a reference to the original project to include (http://mcserve.codeplex.com).
 * 
 * Author       : Lars Krämer ( Xe77a )
 * Website      : http://www.lkraemer.de
 * Project      : MCServe (http://mcserve.codeplex.com)
 * Copyright    : Copyright (c) 2013 lkraemer.de
 * License      : http://mcserve.codeplex.com/license
 * Description  : This part contains general features of the project
 */

using System;
using System.Security.Cryptography;
using System.Text;

namespace MCServeLib
{
    public static class StringFunctions
    {
        public static string Reverse(this string StringData)
        {
            StringBuilder newString = new StringBuilder();

            for (Int32 i = StringData.Length - 1; i >= 0; i--)
                newString.Append(StringData.Substring(i, 1));

            return newString.ToString();
        }

        public static string GetMD5Hash(string value)
        {
            using (var md5 = MD5.Create())
            {
                // ANSI (varchar)
                var valueBytes = Encoding.Default.GetBytes(value);
                var md5HashBytes = md5.ComputeHash(valueBytes);
                var builder = new StringBuilder(md5HashBytes.Length * 2);
                foreach (var md5Byte in md5HashBytes)
                    builder.Append(md5Byte.ToString("X2"));
                return builder.ToString();
            }
        }
    }
}
